package btp.Time;

public class Time {
	int hours;
	int minutes;
	double seconds;
	long rd;
	
	public Time(int hours, int minutes, double seconds){
		this.hours=hours;
		this.seconds=seconds;
		this.minutes=minutes;
		this.rd=0;
	}

	public Time(int hours, int minutes, double seconds, long rd){
		this.hours=hours;
		this.seconds=seconds;
		this.minutes=minutes;
		this.rd=rd;
	}
	
	public int getHours() {
		return hours;
	}
	public void setHours(int hours) {
		this.hours = hours;
	}
	public int getMinutes() {
		return minutes;
	}
	public void setMinutes(int minutes) {
		this.minutes = minutes;
	}
	public double getSeconds() {
		return seconds;
	}
	public void setSeconds(double seconds) {
		this.seconds = seconds;
	}
	public long getRd() {
		return rd;
	}
	public void setRd(long rd) {
		this.rd = rd;
	}
	
	public double toDouble(){
		return rd+hours/24.0+minutes/1440.0+seconds/86400.0;
		
	}
	
	public static Time fromDouble(double d){
		long rd = (int) Math.floor(d);
		double seconds = (d-rd)*86400;
		int minutes = (int) Math.floor(seconds/60);
		seconds -= minutes*60;
		int hours = minutes/60;
		minutes %=60;
		return new Time(hours, minutes, seconds);
	}

	
	public static Time getDifference(Time t1, Time t2){
		double seconds = t1.seconds-t2.seconds;
		int minutes = t1.minutes-t2.minutes;
		int hours = t1.hours - t2.hours;
		long rd = t1.rd - t2.rd;
		if(seconds<0){
			seconds+=60;
			minutes--;
		}
		if(minutes<0){
			minutes+=60;
			hours--;
		}
		if(hours<0){
			hours+=24;
			rd--;
		}
		return new Time(hours, minutes, seconds, rd);
	}
	
	public static Time addTimes(Time t1, Time t2){
		double seconds = t1.seconds-t2.seconds;
		int minutes = t1.minutes-t2.minutes;
		int hours = t1.hours - t2.hours;
		long rd = t1.rd - t2.rd;
		if(seconds>=60){
			seconds-=60;
			minutes++;
		}
		if(minutes>=60){
			minutes-=60;
			hours++;
		}
		if(hours>=24){
			hours-=24;
			rd++;
		}
		return new Time(hours, minutes, seconds, rd);
	}
	
	
}
